//
// Copyright (c) 2017-2025, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//

#pragma once

#include "thread_annotations.h"

/// capability for tracing threads
using ThreadRole CAPABILITY ( "role" ) = bool;

inline void AcquireRole ( ThreadRole R ) ACQUIRE ( R ) NO_THREAD_SAFETY_ANALYSIS
{}

inline void ReleaseRole ( ThreadRole R ) RELEASE ( R ) NO_THREAD_SAFETY_ANALYSIS
{}

class SCOPED_CAPABILITY ScopedRole_c
{
	ThreadRole& m_tRoleRef;

public:
	/// acquire on creation
	inline explicit ScopedRole_c ( ThreadRole& tRole ) ACQUIRE ( tRole )
		: m_tRoleRef ( tRole )
	{
		AcquireRole ( tRole );
	}

	/// release on going out of scope
	~ScopedRole_c() RELEASE()
	{
		ReleaseRole ( m_tRoleRef );
	}
};
